package org.irri.smta.domain;

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Entity
@Table(name = "REPORT_LOG")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ReportLog extends LogAutoIdEntity implements Comparable<ReportLog> {

	private static final long serialVersionUID = 1L;
	private static final Logger LOGGER = LoggerFactory
			.getLogger(ReportLog.class);

	private static final int UUID_LENGTH = 48;
	private static final int MESSAGE_LENGTH = 1000;

	@NotNull
	@Column(name = "UUID", nullable = false, unique = true)
	@Size(min = 1, max = UUID_LENGTH)
	private String uuid;

	@Column(name = "MESSAGE", nullable = true)
	@Size(min = 0, max = MESSAGE_LENGTH)
	private String message;

	public ReportLog() {
		super();
		this.uuid = UUID.randomUUID().toString();
		LOGGER.info("Create report log with UUID = " + this.uuid);
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Override
	public int compareTo(ReportLog o) {
		if (o != null) {
			return this.uuid.compareTo(o.uuid);
		}
		return 0;
	}

}
